package com.lanou.zy.projecta.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lanou.zy.projecta.R;

/**
 * Created by dllo on 15/11/10.
 */
public class UserActivity extends AppCompatActivity implements View.OnClickListener {
    private TextView user_Name_Tv, userCuteName_Tv, userExitLogin_Tv;
    private ImageView userBackToHome_Iv, user_background, userHead_Iv;
    private SharedPreferences sp;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user);
        initView();
        initData();
    }

    private void initView() {
        userHead_Iv = (ImageView) findViewById(R.id.userHead_Iv);
        userHead_Iv.setOnClickListener(this);
        user_Name_Tv = (TextView) findViewById(R.id.user_Name_Tv);
        user_Name_Tv.setOnClickListener(this);
        user_background = (ImageView) findViewById(R.id.user_background);
        user_background.setOnClickListener(this);
        userBackToHome_Iv = (ImageView) findViewById(R.id.userBackToHome_Iv);
        userBackToHome_Iv.setOnClickListener(this);
        userCuteName_Tv = (TextView) findViewById(R.id.userCuteName_Tv);
        userCuteName_Tv.setOnClickListener(this);
        userExitLogin_Tv = (TextView) findViewById(R.id.userExitLogin_Tv);
        userExitLogin_Tv.setOnClickListener(this);
        sp = getSharedPreferences("zy", Context.MODE_PRIVATE);
    }

    private void initData() {
        if (user_background != null) {
            showAlertDialog();
        }
    }

    private void showAlertDialog() {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setTitle("自定义背景"); // 标题文字
        builder.setIcon(R.mipmap.iconfont_beijingguanli); // 标题边上的图标

        builder.setMessage("您可以设置一个自定义背景");
        builder.setPositiveButton("立刻去设置", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(UserActivity.this, "暂时没这个功能，等着版本更新吧", Toast.LENGTH_SHORT).show();

            }
        });

        builder.setNegativeButton("先不设置了", new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                Toast.makeText(UserActivity.this, "不设置你不觉得丑吗？", Toast.LENGTH_SHORT).show();

            }
        });
        builder.show();

    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.user_Name_Tv:
                Toast.makeText(this, "现在版本没这个功能，等着后续更新吧", Toast.LENGTH_SHORT).show();
                break;

            case R.id.userBackToHome_Iv:
                onBackPressed();
                break;

            case R.id.userHead_Iv:
                Toast.makeText(this, "现在版本没这个功能，等着后续更新吧", Toast.LENGTH_SHORT).show();
                break;

            case R.id.user_background:
                Toast.makeText(this, "现在版本没这个功能，等着后续更新吧", Toast.LENGTH_SHORT).show();
                break;

            case R.id.userCuteName_Tv:

                break;

            case R.id.userExitLogin_Tv:
                sp.edit().clear().commit();
                finish();
                break;

        }
    }
}
